<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="资产名称">
              <j-dict-select-tag placeholder="请选择资产名称" v-model="queryParam.assetId" dictCode="zcgl_asset_info,asset_name,id,status>1"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="客户名称">
              <j-dict-select-tag placeholder="请选择客户名称" v-model="queryParam.customerId" dictCode="zcgl_customer_info,name,id"/>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-is-group>
            <a-form-item label="所属公司">
              <j-company-select-tag placeholder="请选择所属公司" v-model="queryParam.companyId"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--<a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-has="'repairInfo:add'" @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button v-has="'repairInfo:export'" type="primary" icon="download" @click="handleExportXls('维修信息')">导出</a-button>
      <a-upload v-has="'repairInfo:import'" name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-button v-has="'repairInfo:temp'" type="primary" icon="download" @click="handleExportXlsTemplate('维修信息模板')">模板下载</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item v-has="'repairInfo:delete'" key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :scroll="{ x: 2500, y: screenHeight}"
        class="j-table-force-wrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">

          <a v-has="'repairInfo:handleUser'" v-if="record.handleStatus < 20" @click="handleOperation('维修人员安排',record, 1)">安排人员</a>
          <a-divider v-has="'repairInfo:handleUser'" v-if="record.handleStatus < 20" type="vertical" />

          <a v-has="'repairInfo:feedback'" v-if="record.handleStatus == 20" @click="handleOperation('维修反馈',record, 2)">反馈</a>
          <a-divider v-has="'repairInfo:feedback'" v-if="record.handleStatus == 20" type="vertical" />

          <a v-has="'repairInfo:look'" @click="handleDetail(record)">查看</a>
          <a-divider v-has="'repairInfo:look'" type="vertical" />

          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item v-has="'repairInfo:edit'" v-if="!record.attentionId && record.handleStatus < 20">
                <a @click="handleEdit(record)">编辑</a>
              </a-menu-item>
<!--              <a-menu-item v-has="'repairInfo:look'">-->
<!--                <a @click="handleDetail(record)">查看</a>-->
<!--              </a-menu-item>-->
              <a-menu-item v-has="'repairInfo:delete'">
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <repairInfo-modal ref="modalForm" @ok="modalFormOk"></repairInfo-modal>
    <RepairInfoOperation-modal ref="modalOperationForm" @ok="modalFormOk"></RepairInfoOperation-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import RepairInfoModal from './modules/RepairInfoModal'
  import RepairInfoOperationModal from './modules/RepairInfoOperationModal'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import JCompanySelectTag from '@comp/jeecg/JCompanySelectTag'

  export default {
    name: "RepairInfoList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JDictSelectTag,
      JCompanySelectTag,
      RepairInfoOperationModal,
      RepairInfoModal
    },
    data () {
      return {
        description: '维修信息管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            fixed: "left",
            customRender: (text, record, index) =>
              `${(this.ipagination.current - 1) * this.ipagination.pageSize + index + 1}`
          },
          {
            title:'资产名称',
            align:"center",
            dataIndex: 'assetId_dictText'
          },
          {
            title: '资产明细',
            align: 'center',
            // fixed:"left",
            // width: 200,
            dataIndex: 'assetSubIds_dictText'
          },
          {
            title:'客户名称',
            align:"center",
            dataIndex: 'customerId_dictText'
          },
          {
            title:'微信信息',
            align:"center",
            dataIndex: 'attentionId_dictText'
          },
          {
            title:'报修标题',
            align:"center",
            dataIndex: 'repairTitle'
          },
          {
            title:'报修内容',
            align:"center",
            dataIndex: 'repairContent'
          },
          {
            title:'报修时间',
            align:"center",
            dataIndex: 'repairDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'处理说明',
            align:"center",
            dataIndex: 'feedbackContent'
          },
          {
            title:'处理时间',
            align:"center",
            dataIndex: 'feedbackDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'维修金额',
            align:"center",
            dataIndex: 'money',
            customRender: function (text) {
              if (!text) {
                text = 0
              }
              return text.toLocaleString("zh-Hans-CN",{style:"currency",currency:"CNY"});
            }
          },
          {
            title:'处理人',
            align:"center",
            dataIndex: 'handleUserId_dictText'
          },
          {
            title:'处理状态',
            align:"center",
            dataIndex: 'handleStatus_dictText'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width: 190,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/zcgl/repairInfo/list",
          delete: "/zcgl/repairInfo/delete",
          deleteBatch: "/zcgl/repairInfo/deleteBatch",
          exportXlsUrl: "/zcgl/repairInfo/exportXls",
          importExcelUrl: "zcgl/repairInfo/importExcel",
          exportXlsTemplate: 'zcgl/repairInfo/exportXlsTemplate'
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {

      handleOperation (title, record, type) {
        this.$refs.modalOperationForm.show(title, record, type);
      },
      initDictConfig(){
        this.toTop = 485
        let height = window.innerHeight - this.toTop
        if (height < 300){
          height = 300
        }
        this.screenHeight = height
        this.addColumns()
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>